package com.example.casper.jnuexperiment2025.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.casper.jnuexperiment2025.R;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.TextureMapView;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;

public class MapFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // 加载布局
        View view = inflater.inflate(R.layout.fragment_map, container, false);
        
        // 初始化地图视图
        TextureMapView mapView = view.findViewById(R.id.map_view);
        TencentMap tencentMap = mapView.getMap();

        LatLng jnuZhuhai = new LatLng(22.250085,113.534612);
        CameraUpdate cameraSigma =
                CameraUpdateFactory.newCameraPosition(new CameraPosition(
                        jnuZhuhai, //中心点坐标，地图目标经纬度
                        20,  //目标缩放级别
                        0, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
                        0)); //目标旋转角 0~360° (正北方为0)
        tencentMap.moveCamera(cameraSigma); //移动地图

        Marker marker = tencentMap.addMarker(new MarkerOptions(jnuZhuhai));
        marker.setTitle("暨南大学珠海校区");
        marker.setSnippet("广东省珠海市香洲区前山路206号");

        tencentMap.setOnMarkerClickListener(marker1 -> {
            // 显示marker的标题和描述信息
            marker1.showInfoWindow();
            return true;
        });

        tencentMap.getUiSettings().setScrollGesturesEnabled(true);
        tencentMap.getUiSettings().setZoomGesturesEnabled(true);
        tencentMap.getUiSettings().setZoomControlsEnabled(true);

        return view;
    }
}